package org.softmed.rest.server;

import org.softmed.filehandling.FileUtil;
import org.softmed.filehandling.cache.FileCache;
import org.softmed.rest.server.config.Config;
import org.softmed.rest.server.config.ConfigReader;
import org.softmed.rest.server.core.boot.Startup;
import org.softmed.rest.server.guice.RESTServerModule;

import com.google.inject.Guice;
import com.google.inject.Injector;

public class Main {

	public static void main(String[] args) throws Throwable {

		if (args.length == 1) {
			System.out.println("Setting fake path : " + args[0]);
			FileUtil.setHackRootPath(args[0]);
		}

		FileCache.getCachedExtensions().add(".groovy");
		FileCache.getCachedExtensions().add(".gc");
		FileCache.getCachedExtensions().add(".xml");

		// for performance, use this
		FileUtil.setFileCache(new FileCache());

		ConfigReader reader = new ConfigReader();
		Config cfg = reader.read();

		FileUtil util = new FileUtil();
		String[] roots = new String[] { util.getRootPath() };

		Injector injector = Guice.createInjector(new RESTServerModule(cfg,
				roots));

		Startup startup = injector.getInstance(Startup.class);
		// app.getSystemBuilder().setDeployAdmin(true);

		startup.execute();
	}
}
